//公有纯虚函数earing()，功能为计算工资收入。
//
#include<iostream>
#include<string>
using namespace std;
class HourlyWorker; //小时工
class PieceWorker;  //计件工
ostream &operator<<(ostream &output,HourlyWorker &h);
ostream &operator<<(ostream &output,PieceWorker &p);
class Employee
{
    public:
    Employee(string n,int w)
    {
        wage=w;
        name=n;
    }
    virtual int earing()=0;
    int wage;
    string name;
};
class HourlyWorker:public Employee      //派生方式 :
{
    public:
    HourlyWorker(string n,int w,int h):Employee(n,m),hour(h){}
    int earing()
    {
        return (wage*hour);
    }
    friend ostream &operator<<(ostream &output,HourlyWorker &h);
    private:
        int hour;
};
ostream &operator<<(ostream &output,HourlyWorker &h)
{
    cout<<"name: "<<h.name<<endl;
    cout<<"earing: "<<h.earing()<<endl;
    return output;
}

class PieceWorker:public Employee
{
    public:
    PieceWorker(string n,int w, int q):Employee(n,w),quantity(q){} //最后不用分号的么？ 逗号分隔符？
    int earing()
    {
        return (wage*quantity);
    }
    friend ostream &operator <<(ostream &output,PieceWorker &p);//友元重载函数在类外定义
    private:
        int quantity;
};//别忘了写分号
ostream &operator <<(ostream &output,PieceWorker &p)//用引用
{
    cout<<"name: "<<p.name<<endl;
    cout<<"earing: "<<p.earing()<<endl;
    return output;
}
int main()
{
    HourlyWorker h("A1",100,150);
    PieceWorker p("A2",300,600);
    HourlyWorker &w1=h;
    cout<<w1;
    cout<<end;
    PieceWorker &w2=p;
    cout<<w2;
    return 0;
}